<?php
/**
 * The MIT License (MIT)
 * Copyright © 2021 Walkline Wang (https://walkline.wang)
 * https://gitee.com/walkline/online-update-manager
 */	

	class query_list_online_upate_manager {
		const query_signin_user = 
			"SELECT
				username,
				`password`
			FROM
				online_update_manager_users
			WHERE
				username = ?
			AND `password` = ?
			LIMIT 1";
		
		const query_user_information = 
			"SELECT
				username,
				`password`
			FROM
				online_update_manager_users
			LIMIT 1";

		const query_append_package =
			"INSERT INTO online_update_manager_packages (package_name) VALUES (?)";
		
		const query_app_information_exist =
			"SELECT
				*
			FROM
				online_update_manager_apps
			WHERE
				`path` = ?
			AND `filename` = ?
			LIMIT 1";

		const query_get_app_file_path =
			"SELECT
				`path`
			FROM
				online_update_manager_apps
			WHERE
				id = ?
			AND package_name = ?
			LIMIT 1";

		const query_append_app =
			"INSERT INTO online_update_manager_apps (
				package_name,
				version,
				note,
				filename,
				path,
				size,
				type,
				is_apk,
				is_wgt,
				is_force_update,
				date
			)
			VALUES
				(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW())";

		const query_remove_app =
			"DELETE
			FROM
				online_update_manager_apps
			WHERE
				id = ?
			AND package_name = ?
			AND `version` = ?
			AND `filename` = ?
			AND size = ?
			AND is_apk = ?
			AND is_wgt = ?
			AND is_force_update = ?
			AND `date` = ?";

		const query_check_package_name =
			"SELECT
				package_name
			FROM
				online_update_manager_packages
			WHERE
				package_name = ?
			LIMIT 1";

		const query_get_all_packages =
			"SELECT
				package_name
			FROM
				online_update_manager_packages
			ORDER BY
				id";
		
		const query_get_all_apps =
			"SELECT
				id,
				`version`,
				`filename`,
				size,
				is_apk,
				is_wgt,
				is_force_update,
				`date`
			FROM
				online_update_manager_apps
			WHERE
				package_name = ?
			ORDER BY
				id DESC";

		const query_get_last_app_information =
			"SELECT
				`version`,
				note,
				`filename`,
				`path`,
				size,
				is_apk,
				is_wgt,
				is_force_update,
				`date`
			FROM
				online_update_manager_apps
			WHERE
				package_name = ?
			ORDER BY
				`date` DESC
			LIMIT 1";

		const query_get_specified_app_information =
			"SELECT
				`version`,
				note,
				`filename`,
				`path`,
				size,
				is_apk,
				is_wgt,
				is_force_update,
				`date`
			FROM
				online_update_manager_apps
			WHERE
				package_name = ?
			AND
				`version` = ?
			ORDER BY
				`date` DESC
			LIMIT 1";

		const query_remove_package =
			"DELETE
			FROM
				online_update_manager_packages
			WHERE
				package_name = ?";
	}
?>
